home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / util2 / vol12n11.zip / OLFONT.ZIP / OLF.C next >
C/C++ Source or Header  |  1993-01-18  |  4KB  |  151 lines

  1. /*--------------------------------------------
  2.    OLF.C -- Easy access to OS/2 outline fonts
  3.             (c) Charles Petzold, 1993
  4.   --------------------------------------------*/
  5.  
  6. #define INCL_GPI
  7. #include <os2.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include "olf.h"
  11.  
  12. PFACELIST GetAllOutlineFonts (HPS hps)
  13.      {
  14.      static PFACELIST pfl ;
  15.      LONG             l, lFonts ;
  16.      PFONTMETRICS     pfm ;
  17.  
  18.                // Check for changed fonts
  19.  
  20.      if (!(QFA_PUBLIC & GpiQueryFontAction (hps, QFA_PUBLIC)) && pfl != NULL)
  21.           return pfl ;
  22.  
  23.                // Delete old structure if necessary
  24.  
  25.      if (pfl != NULL)
  26.           free (pfl) ;
  27.  
  28.                // Determine the number of fonts
  29.  
  30.      lFonts = 0 ;
  31.      lFonts = GpiQueryFonts (hps, QF_PUBLIC, NULL, &lFonts, 0, NULL) ;
  32.  
  33.      if (lFonts == 0)
  34.           return NULL ;
  35.  
  36.                // Allocate memory for FONTMETRICS structures
  37.  
  38.      pfm = (PFONTMETRICS) calloc (lFonts, sizeof (FONTMETRICS)) ;
  39.  
  40.      if (pfm == NULL)
  41.           return NULL ;
  42.  
  43.                // Get all fonts
  44.  
  45.      GpiQueryFonts (hps, QF_PUBLIC, NULL, &lFonts,
  46.                          sizeof (FONTMETRICS), pfm) ;
  47.  
  48.                // Allocate memory for FACELIST structure
  49.  
  50.      pfl = malloc (sizeof (FACELIST)) ;
  51.      pfl->iNumFaces = 0 ;
  52.  
  53.                // Loop through all fonts
  54.  
  55.      for (l = 0 ; l < lFonts ; l++)
  56.           {
  57.                     // Check if outline font
  58.  
  59.           if (pfm[l].fsDefn & FM_DEFN_OUTLINE)
  60.                {
  61.                          // Reallocate FACELIST structure & store face name
  62.  
  63.                pfl = realloc (pfl, sizeof (FACELIST) +
  64.                                    pfl->iNumFaces * FACESIZE) ;
  65.  
  66.                strcpy (pfl->szFacename[pfl->iNumFaces], pfm[l].szFacename) ;
  67.  
  68.                pfl->iNumFaces ++ ;
  69.                }
  70.           }
  71.  
  72.                // Clean up
  73.  
  74.      free (pfm) ;
  75.  
  76.      return pfl ;
  77.      }
  78.  
  79. LONG CreateOutlineFont (HPS hps, LONG lcid, char * szFacename,
  80.                         SHORT fsAttributes, SHORT usCodePage)
  81.      {
  82.      FATTRS fat ;
  83.      LONG   lReturn ;
  84.  
  85.                // Set up FATTRS structure
  86.  
  87.      fat.usRecordLength  = sizeof (FATTRS) ;
  88.      fat.fsSelection     = fsAttributes ;
  89.      fat.lMatch          = 0 ;
  90.      fat.idRegistry      = 0 ;
  91.      fat.usCodePage      = usCodePage ;
  92.      fat.lMaxBaselineExt = 0 ;
  93.      fat.lAveCharWidth   = 0 ;
  94.      fat.fsType          = FATTR_FONTUSE_OUTLINE |
  95.                            FATTR_FONTUSE_TRANSFORMABLE ;
  96.      fat.fsFontUse       = 0 ;
  97.  
  98.      strcpy (fat.szFacename, szFacename) ;
  99.  
  100.                // Create the font
  101.  
  102.      lReturn = GpiCreateLogFont (hps, NULL, lcid, &fat) ;
  103.  
  104.                // If no match, try a symbol code page
  105.  
  106.      if (lReturn == FONT_DEFAULT && usCodePage == 0)
  107.           {
  108.           fat.usCodePage = 65400 ;
  109.  
  110.           lReturn = GpiCreateLogFont (hps, NULL, lcid, &fat) ;
  111.           }
  112.  
  113.      return lReturn ;
  114.      }
  115.  
  116. BOOL ScaleOutlineFont (HPS hps, int iPointSize, int iPointWidth)
  117.      {
  118.      HDC    hdc ;
  119.      LONG   xRes, yRes ;
  120.      POINTL aptl[2] ;
  121.      SIZEF  sizef ;
  122.  
  123.                // Get font resolution in pixels per inch
  124.  
  125.      hdc = GpiQueryDevice (hps) ;
  126.  
  127.      DevQueryCaps (hdc, CAPS_HORIZONTAL_FONT_RES, 1, &xRes) ;
  128.      DevQueryCaps (hdc, CAPS_VERTICAL_FONT_RES,   1, &yRes) ;
  129.  
  130.                // Find desired font size in pixels
  131.  
  132.      if (iPointWidth == 0)
  133.           iPointWidth = iPointSize ;
  134.  
  135.      aptl[0].x = 0 ;
  136.      aptl[0].y = 0 ;
  137.      aptl[1].x = (16 * xRes * iPointWidth + 360) / 720 ;
  138.      aptl[1].y = (16 * yRes * iPointSize  + 360) / 720 ;
  139.  
  140.                // Convert to page coordinates
  141.  
  142.      GpiConvert (hps, CVTC_DEVICE, CVTC_PAGE, 2L, aptl) ;
  143.  
  144.                // Set the character box
  145.  
  146.      sizef.cx = (aptl[1].x - aptl[0].x) << 12 ;
  147.      sizef.cy = (aptl[1].y - aptl[0].y) << 12 ;
  148.  
  149.      return GpiSetCharBox (hps, &sizef) ;
  150.      }
  151.